import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    meta: {
      title: '福瑞企业官网 - 首页',
      keepAlive: true
    }
  },
  // 其他页面路由预留
  {
    path: '/goldmine-forum',
    name: 'goldmineForum',
    component: () => import('../views/Forum.vue')
  },
  {
    path: '/about-furui',
    name: 'aboutFurui',
    component: () => import('../views/AboutFurui.vue')
  },
  {
    path: '/products',
    name: 'products',
    component: () => import('../views/Products.vue')
  },
  {
    path: '/core-technology',
    name: 'coreTechnology',
    component: () => import('../views/CoreTechnology.vue')
  },
  {
    path: '/contact',
    name: 'contact',
    component: () => import('../views/Contact.vue')
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior(to, from, savedPosition) {
    // 滚动到顶部
    return { top: 0 }
  }
})

// 路由守卫设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router